﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace luanvanFinal
{
    class clsStageDetail
    {
        String title;
        int idStage;
        String detail;
        float workPercent;
        public String Title
        {
            get { return title; }
            set { title = value; }
        }
        public int IdStage
        {
            get { return idStage; }
            set { idStage = value; }
        }
        public String Detail
        {
            get { return detail; }
            set { detail = value; }
        }
        public float WorkPercent
        {
            get { return workPercent; }
            set { workPercent = value; }
        }
        public clsStageDetail()
        {
            title = "";
            idStage = 0;
            detail = "";
            workPercent = 0;
        }
        public void insertStageDetail()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertStageDetail", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idStage", SqlDbType.Int).Value = this.idStage;
                sqlcmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = this.title;
                sqlcmd.Parameters.Add("@detail", SqlDbType.NVarChar).Value = this.detail;
                sqlcmd.Parameters.Add("@workPercent", SqlDbType.Float).Value = this.workPercent;                
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public void updateStageDetail()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("updateStageDetail", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idStage", SqlDbType.Int).Value = this.idStage;
                sqlcmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = this.title;
                sqlcmd.Parameters.Add("@detail", SqlDbType.NVarChar).Value = this.detail;
                sqlcmd.Parameters.Add("@workPercent", SqlDbType.Float).Value = this.workPercent;
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public void deleteStageDetail()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteStageDetail", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idStage", SqlDbType.Int).Value = this.idStage;
                sqlcmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = this.title;               
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public void deleteStageDetailByIdStage()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteStageDetailByIdStage", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idStage", SqlDbType.Int).Value = this.idStage;
                
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public DataTable getDataStageDetail(String strSQL)
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }
    }
}

